package recycle.impl;

import org.springframework.stereotype.Service;
import recycle.dao.ProductinfoMapper;
import recycle.pojo.Productinfo;
import recycle.service.ProductinfoService;
import recycle.utils.Page;
import recycle.vo.ProductinfoParam;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
* 描述：商品信息表 服务实现层接口
* @author 孙冉
* @date 2019/07/22
*/
@Service
public class ProductinfoServiceImpl implements ProductinfoService{
	@Resource
	private ProductinfoMapper productinfoMapper;
 	
 	/**
    * 描述：根据Id获取Productinfo对象
    * @param id
    */
    public Productinfo findById(Serializable productId){
    	return productinfoMapper.findById(productId);
    }
    /**
    * 描述：获取所有的Productinfo对象
    */
    public List<Productinfo> findAll(){
    	return productinfoMapper.findAll();
    }

	/**
    * 描述：新增保存Productinfo对象
    */
    public int save(Productinfo productinfo){
    	return  productinfoMapper.save(productinfo);
    }

	/**
    * 描述：根据Id删除Productinfo对象
    * @param id
    */
    public int delete(Serializable productId){
    	return  productinfoMapper.delete(productId);
    }
	
	/**
    * 描述：更新Productinfo对象
    */
    public int update(Productinfo productinfo){
    	return  productinfoMapper.update(productinfo);
    }
    
    /**
     * 根据不确定的条件，动态查询
     */
    public List<Productinfo> query(ProductinfoParam param){
    	return  productinfoMapper.query(param);
    }

	/**
	 * 商品分类列表页面的查询
	 * @param oneCategoryId
	 * @param twoCategoryId
	 * @return
	 */
	@Override
	public List<Productinfo> selectProductInProductList(Integer oneCategoryId, Integer twoCategoryId) {
		return productinfoMapper.selectProductInProductList(oneCategoryId,twoCategoryId);
	}

	/**
     * 根据不确定的条件，动态分页查询
     */
    public Page queryByPage(ProductinfoParam param){
    	Page page = new Page();
    	if(param.isPage()){
			int totalCount = productinfoMapper.getCount(param);
			int totalPageCount = (totalCount-1)/page.getPageSize()+1;
			if(param.getPageIndex()<1){
				param.setPageIndex(1);
			}else if(param.getPageIndex()>totalPageCount){
				param.setPageIndex(totalPageCount);
			}
			List list = productinfoMapper.query(param);

			page.setTotalCount(totalCount);
			page.setTotalPageCount(totalPageCount);
    		page.setPageNo(param.getPageIndex());
    		page.setPageSize(param.getSize());
			page.setList(list);
		}
    	return page;
    	
    }

	@Override
	public Productinfo findByproductName(String productName) {
		return productinfoMapper.findByproductName(productName);
	}

	@Override
	public Productinfo findByproductcategory(String productcategory) {
		return productinfoMapper.findByproductcategory(productcategory);
	}

}
